﻿Imports System.Data
Imports System.Data.SqlClient
Public Class DataProvider
    Shared StrCn As String = "Server = .\SQLEXPRESS;Integrated Security = True;Database = QLDANHMUCPHIM"
    '@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\QLDANHMUCPHIM.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
    Shared Function CreaConnection() As SqlConnection
        Dim cn As SqlConnection = New SqlConnection(StrCn)
        cn.Open()
        Return cn
    End Function
    Shared Function DataTable(sql As String) As DataTable
        Dim cn As New SqlConnection
        cn = CreaConnection()
        Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn)
        Dim dt As New DataTable
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Shared Sub ExcuteQuery(sql As String)
        Dim cn As New SqlConnection
        cn = CreaConnection()
        Dim cmd As SqlCommand = New SqlCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub
End Class
